package com.dawn.module.hospital.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
 * @description:
 * @author: cnsu-cmh
 * @time: 2024/8/7 23:11
 */
@Data
@Component
@ConfigurationProperties(prefix = "cdbpay")
public class CDBPayConfig {

    private String url;

    private String notifyUrl;

    private String notifyChsUrl;

    @NestedConfigurationProperty
    private Abc abc;

    @NestedConfigurationProperty
    private Ali ali;

    @NestedConfigurationProperty
    private AliChs aliChs;

    @NestedConfigurationProperty
    private Wx wx;

    @NestedConfigurationProperty
    private WXChs wxChs;

    @NestedConfigurationProperty
    private DawnPay dawnPay;

    @Data
    public static class Wx {

        private String appid;

        private String mchNo;

        private String appSecret;

        private String wxCode;

        private String wapCode;

        private String barCode;

    }

    @Data
    public static class WXChs {

        private String appid;

        private String mchNo;

        private String appSecret;

        private String jsapiCode;

        private String returnUrl;

        private String notifyUrl;


    }

    @Data
    public static class Abc {

        private String appid;

        private String mchNo;

        private String appSecret;

        private String wxCode;

        private String wapCode;

        private String barCode;

        private String terminalNo;
    }

    @Data
    public static class Ali {

        private String appid;

        private String mchNo;

        private String appSecret;

        private String qrCode;

        private String jsapiCode;

        private String chsCode;
    }

    @Data
    public static class AliChs {

        private String appid;

        private String mchNo;

        private String appSecret;

        private String qrCode;

        private String jsapiCode;

        private String chsCode;
    }

    @Data
    public static class DawnPay {

        private String appid;

        private String mchNo;

        private String appSecret;

        private String wxCode;

        private String wapCode;

        private String barCode;

        private String terminalNo;
    }


    public String getMchNo(String mchType) {
        if (StringUtils.isEmpty(mchType)){
            return null;
        }
        if ("WX".equals(mchType)) {
            return this.getWx().getMchNo();
        }
        if ("ALI".equals(mchType)) {
            return this.getAli().getMchNo();
        }
        if ("WX_CHS".equals(mchType)) {
            return this.getWxChs().getMchNo();
        }
        if ("ALI_CHS".equals(mchType)) {
            return this.getAliChs().getMchNo();
        }
        if ("ABC".equals(mchType)) {
            return this.getAbc().getMchNo();
        }
        if ("DAWN_PAY".equals(mchType)) {
            return this.getDawnPay().getMchNo();
        }
        return null;
    }
}
